package com.da.landlord;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Where;

import com.googlecode.cswish.annotation.cm;
import com.ra.landlord.LandlordOwner;
import com.ra.landlord.LandlordOwnerUser;


/**
 * 费用帐单
 * @author Perter.Z
 *
 */
@Entity
@Table(name="da_dachargebill_record")
public class DaChargeBillRecord implements LandlordOwner{
	
	//费用状态:“已删除”
	public static final Integer STATUS_RENT_DELETE = 0;
	
	//费用状态:“已缴费”
	public static final Integer STATUS_RENT_DONE = 1;
	
	//费用状态:“未缴费”
	public static final Integer STATUS_RENT_TODO = 2;
		
	private Integer id;
	
	@cm("费用所对应的房间")
	private DaRoom room;
	
	@cm("是哪个合约产生的费用")
	private DaAgreement agreement;
	
	@cm("所属房东")
	private LandlordOwnerUser landlordUser;
	
	@cm("应收费用项总额")
	private BigDecimal amountRecv;
	
	@cm("实收费用项总额")
	private BigDecimal amountActual;
	
	@cm("余额")		
	private BigDecimal balance;
	
	@cm("上次余额")		
	private BigDecimal prevBalance;

	@cm("帐单产生日期") 
	private Date dateActual;
	
	@cm("时间段开始")
	private Date dateBeginRecv;
	
	@cm("时间段结束") 
	private Date dateEndRecv;
	
	@cm("帐单明细")
	private List<DaChargeItem> chargeItems;
	
	@cm("帐单备注")
	private String remark;
	
	private Date createTime;
	
	private Integer status;
	
	//transient 是否可以更改收费开始时间
	private Boolean canChangeBeginDate;
	
	//transient
	private Boolean hasRentalOrder;
	
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne
	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordOwnerUser landlordUser) {
		this.landlordUser = landlordUser;
	}

	public BigDecimal getAmountRecv() {
		return amountRecv;
	}

	public void setAmountRecv(BigDecimal amountRecv) {
		this.amountRecv = amountRecv;
	}

	public BigDecimal getAmountActual() {
		return amountActual;
	}

	public void setAmountActual(BigDecimal amountActual) {
		this.amountActual = amountActual;
	}

	public Date getDateActual() {
		return dateActual;
	}

	public void setDateActual(Date dateActual) {
		this.dateActual = dateActual;
	}

	public BigDecimal getBalance() {
		return balance;
	}

	public void setBalance(BigDecimal balance) {
		this.balance = balance;
	}

	
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "chargeBillRecord_id")
	@OrderBy("chargeType asc, id desc")
	public List<DaChargeItem> getChargeItems() {
		return chargeItems;
	}

	public void setChargeItems(List<DaChargeItem> chargeItems) {
		this.chargeItems = chargeItems;
	}

	@ManyToOne
	public DaRoom getRoom() {
		return room;
	}

	public void setRoom(DaRoom room) {
		this.room = room;
	}
	
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@ManyToOne(cascade=CascadeType.REFRESH)
	public DaAgreement getAgreement() {
		return agreement;
	}

	public void setAgreement(DaAgreement agreement) {
		this.agreement = agreement;
	}

	public BigDecimal getPrevBalance() {
		return prevBalance;
	}

	public void setPrevBalance(BigDecimal prevBalance) {
		this.prevBalance = prevBalance;
	}

	public Date getDateBeginRecv() {
		return dateBeginRecv;
	}

	public void setDateBeginRecv(Date dateBeginRecv) {
		this.dateBeginRecv = dateBeginRecv;
	}

	public Date getDateEndRecv() {
		return dateEndRecv;
	}

	public void setDateEndRecv(Date dateEndRecv) {
		this.dateEndRecv = dateEndRecv;
	}

	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@Transient
	public Boolean getCanChangeBeginDate() {
		return canChangeBeginDate;
	}

	public void setCanChangeBeginDate(Boolean canChangeBeginDate) {
		this.canChangeBeginDate = canChangeBeginDate;
	}

	@Transient
	public Boolean getHasRentalOrder() {
		return hasRentalOrder;
	}

	public void setHasRentalOrder(Boolean hasRentalOrder) {
		this.hasRentalOrder = hasRentalOrder;
	}
	
}
